import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

class Column extends Opt {
  constructor() {
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'commissionName',
        title: '佣金单名称',
        minWidth: 220
      },
      {
        field: 'commissionMonth',
        title: '结算月份',
        minWidth: 100
      },
      {
        field: 'settlementTypeStr',
        title: '结算类型',
        minWidth: 150
      },
      {
        field: 'statusStr',
        title: '状态',
        minWidth: 100,
        cell: (row) => {
          return {
            text: {
              color: row.status == 'BACK' || row.status == 'WITHDRAWN' ? 'red' : null
            }
          }
        }
      },
      {
        field: 'invoicingStatusStr',
        minWidth: 100,
        cell: {
          value: (row) => (row.status == 'SETTLED' ? row.invoicingStatusStr : ''),
          text: {}
        },
        header: {
          filter: {
            key: 'invoicingStatus',
            title: '开票状态',
            placeholder: '全部',
            select: {
              key: 'invoicingStatus'
            }
          }
        }
      },
      {
        field: 'settlementStatusStr',
        minWidth: 100,
        cell: {
          value: (row) => (row.status == 'SETTLED' ? row.settlementStatusStr : ''),
          text: {}
        },
        header: {
          filter: {
            key: 'settlementStatus',
            title: '核销状态',
            placeholder: '全部',
            select: {
              key: 'WriteOffStatus'
            }
          }
        }
      },
      {
        field: 'isUploadOurVoucher',
        minWidth: 100,
        cell: {
          value: (row) => (row.status == 'SETTLED' ? row.isUploadOurVoucher : '-'),
          text: {}
        },
        header: {
          filter: {
            key: 'isUploadOurVoucher',
            title: '盖章凭证',
            placeholder: '全部',
            select: {
              options: [
                { key: 1, value: '已上传' },
                { key: 0, value: '未上传' }
              ]
            },
            data: {
              from: (info) => (info.isUploadOurVoucher ? '1' : info.isUploadOurVoucher == false ? '0' : null),
              to: (val) => ({ isUploadOurVoucher: val.value == 1 })
            },
            clearable: true
          }
        }
      },
      {
        field: 'productNames',
        title: '产品',
        minWidth: 150
      },
      {
        field: 'roomCount',
        title: '套数',
        minWidth: 80
      },
      {
        field: 'sumAmount',
        title: '总签约金额(元)',
        minWidth: 140,
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'actualCommissionAmount',
        title: '实际结算佣金(元)',
        minWidth: 140,
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'commitTime',
        title: '提交时间',
        minWidth: 180
      },
      {
        title: '操作',
        width: 230,
        fixed: 'right',
        cell: (item) => {
          return {
            btn: [
              {
                title: '打开',
                event: 'onOpen',
                code: '0111010400',
                visible: item.status == 'DRAFT'
              },
              {
                title: '查看',
                event: 'onDetail',
                code: '0111010100',
                visible: item.status != 'DRAFT'
              },
              {
                title: '重新提交',
                event: 'onResend',
                code: '0111010300',
                visible: item.status == 'BACK'
              },
              {
                title: '上传凭证',
                event: 'onUploadCert',
                visible: item.status == 'SETTLED'
              },
              {
                title: '撤回',
                event: 'onRevocation',
                code: '0111010800',
                visible: item.status == 'NO_SETTLEMENT'
              },
              {
                title: '删除',
                event: 'onDelete',
                code: '0111010500',
                visible: item.status == 'DRAFT' || item.status == 'BACK'
              }
            ]
          }
        }
      }
    ]
  }
}

export default Column
